package com.yjn.thymeleafdemo.controller;

import com.yjn.thymeleafdemo.entity.Student;
import com.yjn.thymeleafdemo.entity.User;
import jakarta.servlet.http.HttpSession;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@Controller
public class ThymeleafController {
    @GetMapping("/index")
    public String index(Model model){
        model.addAttribute("username","admin");
        model.addAttribute("gender","男");
        model.addAttribute("city","广州");
        User user1 = new User(1,"李白","123");
        User user2 = new User(2,"杜甫","123");
        User user3 = new User(3,"白居易","123");
        List<User> users = new ArrayList<>();
        users.add(user1);
        users.add(user2);
        users.add(user3);
        model.addAttribute("users",users);
        model.addAttribute("name","telepone");
        model.addAttribute("user",user1);
        model.addAttribute("score",85);
        return "index";
    }

    @GetMapping("/test")
    public String test(Model model, HttpSession httpSession){
        List<String> list = new ArrayList<>();
        list.add("北京");
        list.add("上海");
        list.add("广州");
        list.add("深圳");
        model.addAttribute("list",list);
        model.addAttribute("date",new Date());
        model.addAttribute("salary",20000.168);
        model.addAttribute("word","helloworld");
        return "test";
    }

    @GetMapping("/test2")
    public String test2(){
        return "test2";
    }


    @GetMapping("/students")
    public String getAllstudents(Model model){
        List<Student> students = new ArrayList<>();
        students.add(new Student(1,"张三","女",20,"计科1班"));
        students.add(new Student(2,"李四","男",21,"计科2班"));
        students.add(new Student(2,"李白","男",18,"计科3班"));
        model.addAttribute("students",students);
        return "students";
    }
}
